new Vue({
    el: '#app',
    data() {
        return {
            form: {
                SQLSerialNumber: "P_business_expert_problem",
                PaginationNumber: 1,//页数
                RowAmount: 20,//每页数据条数
                Condition: '',
                ExtensionCondition: '',
                Sort: 0,
                Category_SerialNumber: '-',
                Expert_SerialNumber: '',
            },
            total: 0,
            tableData: [],	//表格数据
            category: [],
            loading: false,
        }
    },
    mounted() {
        if (getQueryObject().Expert_SerialNumber && getQueryObject().Expert_SerialNumber != "undefined") {
            this.form.Expert_SerialNumber = getQueryObject().Expert_SerialNumber;
            this.getData();
            this.getList(this.form);//前端分页
        }
    },
    methods: {
        onSerach(id) {			//查询方法
            if (id) {
                this.form.Category_SerialNumber = id;
            } else {
                this.form.Sort = this.form.Sort ? 0 : 1;
            }
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getData() {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/salesOrder/queryShoppingTrolleyBySQLSerialNumber`,
                type: 'POST',
                data: {
                    SQLSerialNumber: 'A_business_category_1',
                    Condition: window.btoa(unescape(encodeURIComponent(this.form.Expert_SerialNumber))),
                    ExtensionCondition: ''
                },
                success: function (data) {
                    that.category = [{ Category_Name: '全部', Category_SerialNumber: '-' }, ...data];
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            let sql = "where 1=1\r\n";
            if (form.Category_SerialNumber != '-') {
                sql = sql + "and business_expert_problem.Category_SerialNumber='" + form.Category_SerialNumber + "'\r\n";
            }
            if (form.Expert_SerialNumber) {
                sql = sql + "and business_expert_problem.Expert_SerialNumber='" + form.Expert_SerialNumber + "'\r\n";
            }
            if (form.Sort) {
                sql = sql + "ORDER BY IFNULL(a.Operation_Datetime,business_expert_problem.Operation_Datetime)\r\n";
            } else {
                sql = sql + "ORDER BY IFNULL(a.Operation_Datetime,business_expert_problem.Operation_Datetime) DESC\r\n";
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/salesOrder/getUserAddressForPagination`,
                type: 'GET',
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        handleReply(item){
            window.location.href = './reply.html?Expert_Poblem_SerialNumber=' + item.Expert_Poblem_SerialNumber;
        }
    },
})